import { getDataStandardsList } from '@/api/test/index';
import { DataStandard } from '@/pages/CodeTables/specification';
import { CodeTableStatus, stopwatchColor, dataType } from '@/enums/statusEnum';
const table = reactive<{
  data: [];
  total: number;
  dcChName: string;
  dcEnName: string;
  dcCode: string;
  dcSourceStructure: undefined | string;
  dcStatus: undefined | number;
  num: number;
  size: number;
}>({
  data: [],
  total: 10,
  dcChName: '',
  dcEnName: '',
  dcCode: '',
  dcStatus: undefined,
  dcSourceStructure: undefined,
  num: 1,
  size: 20,
});
const loading = ref<boolean>(true);
// 控制详情弹窗/新增--编辑抽屉
const stanards = reactive<{
  sdialog: boolean;
  drawer: boolean;
}>({
  sdialog: false,
  drawer: false,
});
const getData = async () => {
  loading.value = true;
  const postList = {
    pageNum: table.num,
    pageSize: table.size,
    dcStatus: table.dcStatus,
    dcSourceStructure: table.dcSourceStructure,
    dcEnName: table.dcEnName,
    dcChName: table.dcChName,
    dcCode: table.dcCode,
  };
  console.log('请求发送');
  try {
    const res = await getDataStandardsList(postList);
    res.records.forEach((item: DataStandard) => {
      item.updateTime = new Date(item.updateTime).toLocaleString();
      // 向后端请求数据对象中添加了statusColor用于控制状态颜色
      item.statusColor = stopwatchColor[+item.dcStatus];
      item.dcStatus = CodeTableStatus[+item.dcStatus];
      item.dcDataType = dataType[+item.dcDataType];
    });
    table.data = res.records;
    table.total = res.total;
    loading.value = false;
  } catch (error) {
    loading.value = false;
  }
};
export function getStanardListHooks() {
  return {
    stanards,
    loading,
    table,
    getData,
  };
}
